package logrus.beanmock.scenario;

import logrus.beanmock.ScenarioMethodInterceptor;
import logrus.beanmock.ScenarioController;
import logrus.beanmock.invoker.MethodInvoker;
import logrus.beanmock.invoker.MethodInvokerStatistics;


public class ScenarioControllerImpl implements ScenarioController {

    private final ScenarioMethodInterceptor mockMethodInterceptor;

    private final ScenarioFactory scenarioFactory;

    public ScenarioControllerImpl(final ScenarioMethodInterceptor mockMethodInterceptor, final ScenarioFactory scenarioFactory) {
        this.mockMethodInterceptor = mockMethodInterceptor;
        this.scenarioFactory = scenarioFactory;
    }

    /* (non-Javadoc)
     * @see logrus.beanmock.ScenarioController#begin(java.lang.String)
     */
    public void begin(String... scenarios) {
        Scenario scenario = scenarioFactory.getScenario();
        MethodInvoker methodInvoker = scenario.getMethodInvoker(scenarios);
        mockMethodInterceptor.setMethodInvoker(methodInvoker);
    }

    /* (non-Javadoc)
     * @see logrus.beanmock.ScenarioController#end()
     */
    public MethodInvokerStatistics end() {
        MethodInvoker methodInvoker = mockMethodInterceptor.removeMethodInvoker();
        MethodInvokerStatistics statistics = methodInvoker.getStatistics();
        return statistics;
    }
}
